﻿<UserControl x:Class="XbdSoft.WPFVersion.View.SearchResourceView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:interopControl="clr-namespace:XbdSoft.InteropControls;assembly=XbdSoft.InteropControls"
             xmlns:WPFVersion="clr-namespace:XbdSoft.WPFVersion.ViewModel"
             mc:Ignorable="d" Name="Root" FontSize="13" Loaded="Root_Loaded"
              d:DesignHeight="400" d:DesignWidth="600">
    <Grid>
        <Grid.Resources>
            <WPFVersion:AgesConverter x:Key="agesConverter"/>
            <WPFVersion:ImageSourceConverter x:Key="imageSourceConverter"></WPFVersion:ImageSourceConverter>
            <Style x:Key="imageButton" TargetType="Button">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Border BorderThickness="0" BorderBrush="Gray" Background="{TemplateBinding Background}">
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <Style TargetType="TextBlock">
                <Setter Property="FontSize" Value="12"></Setter>                
            </Style>
            <Style TargetType="{x:Type ListBoxItem}">
                <Setter Property="FontSize" Value="12"></Setter>
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Background" Value="#A2D2EB"></Setter>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Grid.Resources>
        <Grid.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,-0.2">
                <GradientStop Color="#FFA0E8FF"/>
                <GradientStop Color="#FFFEFEFE" Offset="1"/>
            </LinearGradientBrush>
        </Grid.Background>
        <Grid.RowDefinitions>
            <RowDefinition Height="25"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="25"/>
        </Grid.RowDefinitions>
        <StackPanel Width="600" Orientation="Horizontal" HorizontalAlignment="Left">
            <StackPanel>
                <ComboBox ItemsSource="{Binding AllAges}"  Width="100" Height="22" Margin="10,0,0,0"  DisplayMemberPath="Text"  SelectedValuePath="Value" SelectedIndex="{Binding SelectedAgeIndex,Mode=TwoWay}">

                    <ComboBox.Background>
                        <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                            <GradientStop Color="#FFCDCDCD" Offset="0"/>
                            <GradientStop Color="#FFEBEBEB" Offset="0.004"/>
                            <GradientStop Color="#FFEFA54A" Offset="0.543"/>
                            <GradientStop Color="#FFF9D6AA" Offset="1"/>
                            <GradientStop Color="#FFF9D6AA"/>
                        </LinearGradientBrush>
                    </ComboBox.Background>
                </ComboBox>
            </StackPanel>
            <StackPanel Margin="10,0,0,0" Orientation="Horizontal" HorizontalAlignment="Left">
                <CheckBox Height="16" HorizontalAlignment="Left" Name="SelectAllCheckbox" Content="全选" VerticalAlignment="Top" Margin="0,4,0,0"
                        Command="{Binding SelectAllResourceCommand}" CommandParameter="{Binding ElementName=SelectAllCheckbox,Path=IsChecked}" />
                <CheckBox Height="16" HorizontalAlignment="Left" Name="SelectOthersCheckbox" Content="反选" VerticalAlignment="Top" Margin="0,4,0,0"
                        Command="{Binding SelectOthersResourceCommand}"/>
                <Button Name="DownloadSelectedButton" Style="{StaticResource imageButton}" Margin="5,0,0,0"  Cursor="Hand" ToolTip="下载已选"  Width="20" Height="16"
                        Command="{Binding DownloadAllSelectedResourceCommand}">
                    <Button.Background>
                        <ImageBrush ImageSource="/Images/download.png">
                        </ImageBrush>
                    </Button.Background>
                </Button>
            </StackPanel>
            <StackPanel Margin="20,0,0,0" Orientation="Horizontal" HorizontalAlignment="Right">
                <Label Content="关键字："  HorizontalAlignment="Left"   Name="label1" VerticalAlignment="Top" />
                <TextBox Height="23" HorizontalAlignment="Left" Name="KeyWordTextBox"  KeyDown="KeyWordTextBox_KeyDown" VerticalAlignment="Top" Width="142" 
                         TextChanged="KeyWordTextBox_TextChanged"/>                
                <Button Content="搜索" Name="SearchButton" Margin="10,0,0,0" Height="23" HorizontalAlignment="Left"   VerticalAlignment="Top" Width="75"
                    Command="{Binding Path=SearchCommand}" CommandParameter="{Binding ElementName=KeyWordTextBox,Path=Text}">
                    <Button.Background>
                        <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                            <GradientStop Color="#FFCDCDCD" Offset="0"/>
                            <GradientStop Color="#FFEBEBEB" Offset="0.004"/>
                            <GradientStop Color="#FFEFA54A" Offset="0.543"/>
                            <GradientStop Color="#FFF9D6AA" Offset="1"/>
                            <GradientStop Color="#FFF9D6AA"/>
                        </LinearGradientBrush>
                    </Button.Background>
                </Button>
                
            </StackPanel> 
        </StackPanel>
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="150" MaxWidth="250"/>
                <ColumnDefinition Width="2"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"></RowDefinition>
                <RowDefinition Height="3"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
            </Grid.RowDefinitions>
            <ListBox Grid.Column="0"  Grid.Row="0" Background="Transparent" ItemsSource="{Binding Path=AudioClasses,Mode=OneWay}"
                      Margin="0,0,0,0" BorderThickness="0,1,0,0" BorderBrush="LightBlue"
                      DisplayMemberPath="Name" 
                     SelectedIndex="{Binding SelectedAudioClassIndex, Mode=TwoWay}"
                      SelectionMode="Single"></ListBox>
            <StackPanel Grid.Row="2" Grid.Column="0" Orientation="Vertical" Background="White">
                <WindowsFormsHost x:Name="winMediaPlayerHost" Width="150" Height="65"  Visibility="Collapsed">
                    <interopControl:WinMediaPlayer x:Name="winMediaPlayer"></interopControl:WinMediaPlayer>
                </WindowsFormsHost>
            </StackPanel>
            <Border Margin="0" Padding="0" Background="Gray" HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="0" Grid.RowSpan="3"></Border>
            <ListBox Grid.Column="2" Grid.Row="0" Grid.RowSpan="3" Background="Transparent" ItemsSource="{Binding Path=AudioResources,Mode=OneWay}" BorderThickness="0,1,0,1"
                        BorderBrush="LightBlue">
                <ListBox.ItemTemplate >
                    <DataTemplate>
                        <Border  BorderThickness="0,0,0,1" BorderBrush="LightBlue" Padding="2,2,2,2">
                            <Grid HorizontalAlignment="Stretch" Width="530" >
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="30"/>
                                    <ColumnDefinition Width="50"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="100"/>
                                </Grid.ColumnDefinitions>
                                <CheckBox Name="SelectToDownloadCheckBox" IsChecked="{Binding Path=Selected,Mode=TwoWay}" VerticalAlignment="Center" Grid.Column="0" Grid.Row="0" />
                                <Image Stretch="Uniform" Grid.Column="1" Grid.Row="0" Source="{Binding Path=ThumbnailImgUrl,Converter={StaticResource imageSourceConverter}}"></Image>
                                <DockPanel  Grid.Column="2" Grid.Row="0" LastChildFill="True">
                                    <TextBlock  DockPanel.Dock="Top" Padding="5,0,0,0" Width="350"  TextWrapping="Wrap" Text="{Binding Title}"></TextBlock>
                                    <Grid VerticalAlignment="Center">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="3*"/>
                                            <ColumnDefinition Width="3*"/>
                                            <ColumnDefinition Width="4*"/>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Grid.Column="0" HorizontalAlignment="Center"  Foreground="Gray">
                                    <TextBlock.Text>
                                        <Binding Path="Time" StringFormat="时间:{0}"></Binding>
                                    </TextBlock.Text>
                                        </TextBlock>
                                        <TextBlock Grid.Column="1" HorizontalAlignment="Center" Foreground="Gray">
                                            <TextBlock.Text>
                                                <Binding Path="BrowserCount" StringFormat="浏览次数:{0}"></Binding>
                                            </TextBlock.Text>
                                        </TextBlock>
                                        <TextBlock Grid.Column="2" HorizontalAlignment="Right" Grid.Row="2" Text="所属年龄段"  Foreground="Gray">
                                            <TextBlock.ToolTip>
                                                <Binding Path="SuitableAges" Converter="{StaticResource agesConverter}"></Binding>
                                            </TextBlock.ToolTip>
                                        </TextBlock> 
                                        <!--<Image Grid.Column="2" HorizontalAlignment="Center" Stretch="Uniform" Source="/Images/yc.gif"></Image>-->
                                    </Grid>
                                </DockPanel>
                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Grid.Column="3" Grid.Row="0">
                                    <Button Style="{StaticResource imageButton}"  Margin="2,0,2,0" Cursor="Hand" ToolTip="试听" Width="20" Height="16"
                                        Command="{Binding ElementName=Root, Path=TryListenCommand}" CommandParameter="{Binding ID}"
                                        >
                                        <Button.Background>
                                            <ImageBrush ImageSource="/Images/trylisten.png">
                                            </ImageBrush>
                                        </Button.Background>
                                    </Button>
                                    <Button  Style="{StaticResource imageButton}" Margin="2,0,2,0" Cursor="Hand" ToolTip="下载"  Width="20" Height="16"
                                          Command="{Binding ElementName=Root, Path=DownloadCommand}" CommandParameter="{Binding ID}">
                                        <Button.Background>
                                            <ImageBrush ImageSource="/Images/download.png">
                                            </ImageBrush>
                                        </Button.Background>
                                    </Button>
                                </StackPanel>
                            </Grid>
                        </Border>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>
        <StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">

            <Button Content="上一页" FontSize="11"  Height="23" HorizontalAlignment="Left" BorderBrush="Transparent" Background="Transparent" 
                    Command="{Binding Path=PrePageCommand}"
                    BorderThickness="0"  VerticalAlignment="Center" />
            <Button Content="下一页" FontSize="11"  Height="23" HorizontalAlignment="Left" VerticalAlignment="Center" BorderBrush="Transparent" 
                     Command="{Binding Path=NextPageCommand}"
                    Background="Transparent" BorderThickness="0"  />
            <TextBlock Margin="5,0,5,0" FontSize="11"  Padding="0,4,0,0"  Height="23" HorizontalAlignment="Right" Name="textBlock1" VerticalAlignment="Top" >
                <TextBlock.Text>
                    <Binding Path="TotalPageCount"  StringFormat="共{0}页"></Binding>
                </TextBlock.Text>
            </TextBlock>
            <TextBlock Height="23" FontSize="11" Padding="0,4,0,0"  HorizontalAlignment="Left"  Text="第"  VerticalAlignment="Center" />
            <TextBox Height="23" FontSize="11"  Padding="0,4,0,0" Width="20" Name="CurrentPageIndexTextBox" Text="{Binding Path=CurrentPageIndex,Mode=OneWay}"  VerticalAlignment="Center" />
            <TextBlock Height="23" FontSize="11" Padding="0,4,0,0"  HorizontalAlignment="Left" Text="页" VerticalAlignment="Center" />
            <Button Content="跳转" FontSize="11" Height="23" HorizontalAlignment="Left" BorderBrush="Transparent" Background="Transparent" 
                    Command="{Binding Path=GoPageCommand}" CommandParameter="{Binding ElementName=CurrentPageIndexTextBox,Path=Text}"
                    BorderThickness="0"  VerticalAlignment="Center"  />
            <!--<TextBox Height="23" Margin="423,0,151,0" Name="textBox1" VerticalAlignment="Top" />-->
        </StackPanel>
        <Border Name="MaskBorder" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="1" Grid.RowSpan="3"  Panel.ZIndex="1000" >
            <Border.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,-0.2">
                    <GradientStop Color="#FFA0E8FF"/>
                    <GradientStop Color="#FFFEFEFE" Offset="1"/>
                </LinearGradientBrush>
            </Border.Background>
            <TextBlock FontSize="13" VerticalAlignment="Center" HorizontalAlignment="Center">加载中... ...</TextBlock>            
        </Border>
    </Grid>
</UserControl>
